package gw;

import gw.comp.combobox.Boton;
import gw.comp.combobox.ComboBoxBean;
import gw.comp.combobox.ComboBoxPrincipal;
import gw.comp.combobox.ValorObservable;
import gw.comp.menubar.MenuBarPrincipal;
import gw.comp.statusbar.StatusBarPrincipal;
import gw.comp.tabbedpane.TabbedPanePrincipal;
import gw.comp.toolbar.ToolBarPrincipal;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author jcastillo
 */
public class FrmVentana extends gw.AbstractVentana {

    private static TabbedPanePrincipal tabContenedor = new TabbedPanePrincipal();
    ComboBoxPrincipal comboBoxPrincipal;
    ValorObservable vo;
    
    public FrmVentana() {
        this("Titulo principal", null);
    }

    public FrmVentana(String titulo, Image fondo) {
        super(titulo);
        initComponents();
        setJMenuBar(new MenuBarPrincipal());
        if (fondo != null) {
            setFondo();
        }
        pnlToolBar.add(new ToolBarPrincipal());
        pnlContenedor.add(getTabContenedor());
        pnlStatusBar.add(new StatusBarPrincipal());


        JPanel panel = new JPanel();
        ArrayList<ComboBoxBean> lista = new ArrayList<ComboBoxBean>();
        ComboBoxBean comboBoxBean;
        comboBoxBean = new ComboBoxBean(1, "Uno");
        lista.add(comboBoxBean);
        comboBoxBean = new ComboBoxBean(2, "Dos");
        lista.add(comboBoxBean);
        comboBoxBean = new ComboBoxBean(3, "Tres");
        lista.add(comboBoxBean);
        comboBoxBean = new ComboBoxBean(4, "Cuatro");
        lista.add(comboBoxBean);
        comboBoxPrincipal = new ComboBoxPrincipal(lista);
        comboBoxPrincipal.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent ie) {
                vo.setnValor(comboBoxPrincipal.getSelectedItem().toString());
            }
        });

        panel.add(comboBoxPrincipal);
        vo = new ValorObservable(comboBoxPrincipal.getSelectedItem().toString());
        Boton boton = new Boton(vo);
        vo.addObserver(boton);
        boton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                JOptionPane.showMessageDialog(null, comboBoxPrincipal.getCodigo());
            }
        });
        boton.setText("Cual es el codigo de: ");
        panel.add(boton);
        getTabContenedor().agregarTab(panel, "Titulo");
    }

    private void setFondo() {
    }

    public static TabbedPanePrincipal getTabContenedor() {
        return tabContenedor;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        pnlToolBar = new javax.swing.JPanel();
        pnlContenedor = new javax.swing.JPanel();
        pnlStatusBar = new javax.swing.JPanel();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        pnlToolBar.setBorder(null);
        pnlToolBar.setLayout(new javax.swing.BoxLayout(pnlToolBar, javax.swing.BoxLayout.LINE_AXIS));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(pnlToolBar, gridBagConstraints);

        pnlContenedor.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlContenedor.setLayout(new javax.swing.BoxLayout(pnlContenedor, javax.swing.BoxLayout.LINE_AXIS));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(pnlContenedor, gridBagConstraints);

        pnlStatusBar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlStatusBar.setLayout(new javax.swing.BoxLayout(pnlStatusBar, javax.swing.BoxLayout.LINE_AXIS));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(pnlStatusBar, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel pnlContenedor;
    private javax.swing.JPanel pnlStatusBar;
    private javax.swing.JPanel pnlToolBar;
    // End of variables declaration//GEN-END:variables
}